package blackstar.performance.transform.instrutment;

import org.objectweb.asm.MethodVisitor;

import blackstar.performance.InvokeDetailPerformance;

/**
 * @author raywu (ayufox@gmail.com)
 * 
 */
public class InvokeDetailPerformanceMethodAdapter extends
		AbstractPerformanceMethodAdapter
{
	private final static int MONITOR_STACK = 4;////最少需要的栈大小,包括2个string引用+1个异常引用/2个返回值(譬如long)

	public InvokeDetailPerformanceMethodAdapter(String className, String methodName,
			int access, String desc, MethodVisitor mv)
	{
		super(className, methodName, access, desc, mv);
	}

	public void visitMaxs(int maxStack, int maxLocals)
	{
		super.visitMaxs(Math.max(MONITOR_STACK, maxStack), maxLocals);
	}

	protected void addBeginInvoke()
	{
		// blackstar.performance.InvokeDetailPerformance.entryMethod(className, methodName);
		mv.visitLdcInsn(this.className);
		mv.visitLdcInsn(this.methodName);
		mv.visitMethodInsn(INVOKESTATIC, InvokeDetailPerformance.CLASS_NAME,
				InvokeDetailPerformance.ENTRY_METHOD,
				InvokeDetailPerformance.METHOD_SYNTAX);
	}

	protected void addEndInvoke()
	{
		// blackstar.performance.InvokeDetailPerformance.exitMethod(className, methodName);
		mv.visitLdcInsn(this.className);
		mv.visitLdcInsn(this.methodName);
		mv.visitMethodInsn(INVOKESTATIC, InvokeDetailPerformance.CLASS_NAME,
				InvokeDetailPerformance.EXIT_METHOD,
				InvokeDetailPerformance.METHOD_SYNTAX);
	}
}